﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Cangku.cy
{
    public partial class XiuG : Form
    {
        public int ckid;
        public string ckmc;
        public XiuG()
        {
            InitializeComponent();
        }

        private void qux_Click(object sender, EventArgs e)
        {
            CKMC.Clear();
        }

        private void qued_Click(object sender, EventArgs e)
        {
            string id = this.CKID.Text.Trim();
            string bh = this.CKBH.Text.Trim();
            string mc = this.CKMC.Text.Trim();
            DBHelper db = new DBHelper();
            if (mc!=ckmc)
            {
                string sql = string.Format("update Information set CKID='{0}',CKname='{1}',CKzhuang='' where ID='{2}'", bh, mc, id);
                bool result = db.ExcuteSql(sql);
                if (result)
                {
                    MessageBox.Show("修改成功！");
                    CKXX ower = (CKXX)this.Owner;
                    ower.LoadCangku();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败！");
                }
            }
            else
            {
                MessageBox.Show("请输入修改内容！");
            }
                

            
        }
        private void XiuG_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=CK;Integrated Security=True");
            string sql = string.Format("select * from Information where ID='{0}'", ckid);
            SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
            DataTable dt = new DataTable();
            dap.Fill(dt);
            this.CKID.Text = dt.Rows[0]["ID"].ToString();
            this.CKBH.Text = dt.Rows[0]["CKID"].ToString();
            ckmc = this.CKMC.Text = dt.Rows[0]["CKname"].ToString();
        }
    }
}
